package cc.bluemc.modules.weixin.service;

import com.gson.bean.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 微信菜单类功能业务
 * 
 * 
 */
@Service
@Transactional(readOnly = true)
public class MenuService
{
	private static Logger logger = LoggerFactory.getLogger(MenuService.class);
	@Autowired
	private WxuserService wxuserService;
	@Autowired
	private ThreadPoolTaskExecutor taskScheduler;
	/**
	 * 首页
	 * 
	 * @param msg
	 * @return
	 */
	public OutMessage home(InMessage msg,String appId)
	{
		TextOutMessage outMessage = new TextOutMessage("success");
//		List<Articles> list = new ArrayList<Articles>();
//		String t = "Dream，请别让我错过你！！！";
//		String p = "";
//		String u = "";
//		String d="我的生命因你而精彩。梦想是迷茫中的灯塔，是坚强的源泉，是信念的伴侣，是生的意义，是成功的曙光";
//		Articles a = new Articles(t, d, p, u);
//		list.add(a);
//		NewsOutMessage newsOutMessage = new NewsOutMessage();
//		newsOutMessage.setArticles(list);
		return outMessage;
	}

	/**
	 * 文字自动回复
	 * @param msg
	 * @return
	 */
	public OutMessage replyText(InMessage msg,String appId){
		String content = msg.getContent();
		if ("success".equals(content)) {
			TextOutMessage outMessage = new TextOutMessage("success");
			return outMessage;
		}
		return null;
	}
	/**
	 * 微调研
	 * 
	 * @param msg
	 * @return
	 */
	public OutMessage survey(InMessage msg)
	{
		List<Articles> list = new ArrayList<Articles>();
		String t = "微调研";
		String d = null;
		String p = "";
		String u ="web/survey/survey_webSurveyList.action?openId="
				+ msg.getFromUserName();
		Articles a = new Articles(t, d, p, u);
		list.add(a);

//		List<CommunityinfoSurveyEntity> surveyList = surveyService.findNewSurvey(msg.getFromUserName());
//		if (null != surveyList)
//		{
//			for (CommunityinfoSurveyEntity bean : surveyList)
//			{
//				String t1 = bean.getSurvey().getName();
//				String d1 = null;
//				String p1 = WeixinConstant.WebImgBasePath + "survey.jpg?" + WeixinConstant.SYSTEM_VERSION;
//				String u1 = WeixinConstant.WEBBASEPATH
//						+ "web/survey/survey_enterSurvey.action?survey.id="
//						+ bean.getSurvey().getId()
//						+ "&subjectPage=-1&openId="
//						+ msg.getFromUserName();
//				if (StringUtils.isNotBlank(msg.getCache()))
//				{
//					u1 += "&token=" + msg.getCache();
//				}
//				Articles a1 = new Articles(t1, d1, p1, u1);
//				list.add(a1);
//			}
//		}
		NewsOutMessage out = new NewsOutMessage();
		out.setArticles(list);
		return out;
	}
}
